package com.bigShen.pattern.prototype.deepClone;

import com.bigShen.pattern.prototype.JinGuBang;

import java.io.*;

/**
 * Created by lei.shen on 2018/9/23.
 */
public class DeepQiTianDaSheng implements Cloneable, Serializable{

    private String type;

    private String name;

    private JinGuBang jinGuBang;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public JinGuBang getJinGuBang() {
        return jinGuBang;
    }

    public void setJinGuBang(JinGuBang jinGuBang) {
        this.jinGuBang = jinGuBang;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return this.deepClone();
    }

    private DeepQiTianDaSheng deepClone() {

        DeepQiTianDaSheng clone = null;

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(this);
            oos.flush();
            oos.close();

            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()) ;
            ObjectInputStream ois = new ObjectInputStream(bais);
            clone = (DeepQiTianDaSheng) ois.readObject();
            ois.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return clone;

    }


}
